/*******************************************************************************
ControllerManager.cpp

Notes:
*******************************************************************************/

#include "ControllerManager.h"

// Initialize the controller manager instance
ControllerManager* ControllerManager::m_pInstance = NULL;

//	GetManager(void)
//		Creates/returns a single instance of the controller manager
ControllerManager* ControllerManager::GetManager(void)
{
	// If a controller manager hasn't been created...
	if(NULL == m_pInstance)
	{
		// ... create a new one
		m_pInstance = new ControllerManager();
	} // if

	// Return the instance of the controller manager
	return m_pInstance;
} // GetManager

//	~ControllerManager(void)
//		Cleans up the controller manager
ControllerManager::~ControllerManager(void)
{
	// If we've created an instance, clean it up
	if(NULL != m_pInstance)
	{
		delete m_pInstance;
		m_pInstance = NULL;
	}

	// Clean up the controller list
	m_controllerList.clear();
} // ~ControllerManager

//	Add(Controller* pController)
//		Adds a controller to the list to be updated
//			pController - A pointer to the controller
void ControllerManager::Add(Controller* pController)
{
	// Add the controller to the list
	m_controllerList.push_back(pController);
} // Add

//	Update(const sf::Input& input)
//		Updates the list of controllers
//			input - A reference to the user input
void ControllerManager::Update(const sf::Input& input)
{
	// Updates each controller
	for(unsigned int index = 0; index < m_controllerList.size(); index++)
	{
		m_controllerList[index]->Update(input);
	} // for
} // Updatae